import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common';
import { appConfig } from './app.config';
import { TypeOrmModule } from '@nestjs/typeorm';
import { UserController } from './controllers/user.controller';
import { UserService } from './services/user.service';
import { DecodeMiddleware } from './middlewares/decode.middleware';
import { MulterModule } from '@nestjs/platform-express';

@Module({
  imports: [
    TypeOrmModule.forRoot(appConfig.sqlConfig),
    MulterModule.registerAsync({
      useFactory: () => ({
        dest: '../public/temp',
      }),
    })
  ],
  controllers: [UserController],
  providers: [UserService]
})
export class AppModule implements NestModule {
  configure(consumer: MiddlewareConsumer) {
    consumer
      .apply(DecodeMiddleware)
      .forRoutes(UserController);
  }
}
